<template>
	<view>
		<u-loading-page :loading="true" loading-text="正在加载"></u-loading-page>
	</view>
</template>

<script>
	import store from '@/store/index.js'	
	export default {
		data() {
			return {
				title: 'Hello',
				code:'',
			}
		},
		onShow() {
			this.login();
			// this.checkLogin();
		},
		methods: {
			login(){
				// console.log(123);
				uni.login({
				  provider: 'weixin', //使用微信登录
				  success: function (loginRes) {
				    console.log(loginRes.code);
					uni.$u.http.get('https://wdzbx.zsbike.com.cn:10787/api.v1/Url?code='+loginRes.code).then(res => {
						console.log(res.data.Status);
						  // uni.clearStorageSync();
							if(res.data.Status==1){
								// console.log(res.data.Data);
								try {
									uni.setStorageSync('userinfo.userid', res.data.Data.userinfo.username);
									uni.setStorageSync('userinfo.nickname', res.data.Data.userinfo.nickname);
									uni.setStorageSync('userinfo.group_id', res.data.Data.userinfo.group_id);
									store.commit('login');
									uni.navigateTo({
										url: "/pages/index/code"
									});
								} catch (e) {
									// error
								}
							}else{
								uni.clearStorageSync();
								uni.navigateTo({
									url: "/pages/index/not"
								});
							}
						}).catch(err => {
						
						})
				  }
				});
			},
		}
	}
</script>
